package com.amex.uam.util;

import java.util.Properties;

public class PropertyManager {

	private static boolean SSL;
	private static boolean TLS;

	private static final String SMTP = "smtp";
	private static Properties prop_send;
	private static Properties prop_send_gmail;
	private static Properties prop_send_hotmail;
	private static Properties prop_receive;
	private static Properties prop_receive_gmail;
	private static Properties prop_receive_hotmail;

	static
	{
		prop_send = new Properties();
		prop_send_gmail = new Properties();
		prop_send_hotmail = new Properties();
		prop_receive = new Properties();
		prop_receive_gmail = new Properties();
		prop_receive_hotmail = new Properties();

		prop_send.put("mail.smtp.port", "25"); // default smtp
		prop_send.put("mail.Transport.protocol", SMTP);

		
		prop_send_gmail.putAll(prop_send); // add default smtp
		prop_send_gmail.put("mail.smtp.socketFactory.port", "465");
		prop_send_gmail.put("mail.smtp.socketFactory.fallback", "false");
		prop_send_gmail.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

		prop_send_hotmail.putAll(prop_send); // add default smtp
		prop_send_hotmail.put("mail.smtp.starttls.enable", "true");

		prop_receive_gmail.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
		prop_receive_gmail.put("mail.pop3.socketFactory.fallback", "false");
		prop_receive_gmail.put("mail.pop3.port", "995");
		prop_receive_gmail.put("mail.pop3.socketFactory.port", "995");

		// gmail equals hotmail when receive mail
		prop_receive_hotmail.putAll(prop_receive_gmail);

	}

	public static Properties getSendProperty(String emailAddress, String emailHost)
	{

		Properties prop = null;
		emailAddress = emailAddress.toLowerCase();

		if (emailAddress.trim().indexOf("@gmail.com") != -1)
			prop = prop_send_gmail;
		else if (emailAddress.trim().indexOf("@live.cn") != -1)
			prop = prop_send_hotmail;
		else if (emailAddress.trim().indexOf("@msn.com") != -1)
			prop = prop_send_hotmail;
		else if (emailAddress.trim().indexOf("@live.com") != -1)
			prop = prop_send_hotmail;
		else if (emailAddress.trim().indexOf("@hotmail.com") != -1)
			prop = prop_send_hotmail;
		else
			prop = prop_send;
		
		prop.put("mail.smtp.host", emailHost);

		return prop;

	}

	public static Properties getReceiveProperty(String ext, String host)
	{
		Properties prop = null;
		ext = ext.toLowerCase();

		if (ext.trim().indexOf("@gmail.com") != -1)
			prop = prop_receive_gmail;
		else if (ext.trim().indexOf("@live.cn") != -1)
			prop = prop_receive_hotmail;
		else if (ext.trim().indexOf("@msn.com") != -1)
			prop = prop_receive_hotmail;
		else if (ext.trim().indexOf("@live.com") != -1)
			prop = prop_receive_hotmail;
		else if (ext.trim().indexOf("@hotmail.com") != -1)
			prop = prop_receive_hotmail;
		else
			prop = prop_receive;
		return prop;

	}

	public static void main(String[] args)
	{
		String host = "xxx";

		String ext = "xxx@hotmail.com";

		System.out.println(getSendProperty(ext, host).size());

		System.err.println(getReceiveProperty(ext, host).size());

	}
}
